<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="ui.xhtml">

	<ui:define name="head">
		<style type="text/css">
.ui-confirm-dialog-severity {
	margin: 0 7px 7px 0;
}
</style>
	</ui:define>
	<ui:define name="content">
		<p:panel header="#{msg.menu_repositories}" id="panel">
			<h:form>
				<p:commandButton value="#{msg.label_newrepository}"
					onclick="dlgNew.show()" icon="add" />
			</h:form>
			<!-- Formulario nuevo repositorio -->
			<h:form id="frmNew">
				<p:dialog header="#{msg.label_newrepository}" widgetVar="dlgNew"
					resizable="false" modal="true" id="newDialog">
					<p:growl id="newGrowl" showDetail="false" sticky="true" />
					<h:panelGrid columns="2" style="margin-bottom:10px; width: 400px;"
						cellpadding="" id="matchGrid">
						<h:outputLabel for="name" value="#{msg.label_name}: " />
						<p:inputText id="name" required="true" size="30"
							value="#{RepositoriesBean.name}" />
						<h:outputLabel for="description"
							value="#{msg.label_description}: " />
						<p:inputTextarea rows="6" cols="33" id="description"
							value="#{RepositoriesBean.description}" />
						<h:outputLabel for="organization"
							value="#{msg.label_organization}: " />
						<p:autoComplete value="#{RepositoriesBean.organization}"
							id="organization"
							completeMethod="#{RepositoriesBean.completeOrganization}" var="o"
							itemLabel="#{o.name}" itemValue="#{o}"
							converter="OrganizationConverter" forceSelection="true"
							dropdown="true" />
						<h:outputText value="#{msg.link_storage}: " />
						<p:selectOneListbox id="scroll"
							value="#{RepositoriesBean.storage}" converter="StorageConverter"
							style="height:100px">
							<f:selectItems value="#{RepositoriesBean.listStorage}" var="s"
								itemLabel="#{s.name}" itemValue="#{s}" />
						</p:selectOneListbox>
						<f:facet name="footer">
							<p:commandButton id="submitButton" value="#{msg.label_save}"
								icon="save" actionListener="#{RepositoriesBean.save}"
								oncomplete="dlgNew.hide(); confirmationProperties.show();" />
							<p:commandButton value="#{msg.label_cancel}"
								oncomplete="dlgNew.hide();" icon="cancel" />
						</f:facet>
					</h:panelGrid>
				</p:dialog>
			</h:form>
			<!-- Formulario para saber si o no agrega propiedades -->
			<h:form prependId="false">
				<p:growl id="propertiesGlow" />
				<p:confirmDialog id="confirmDialog"
					message="#{msg.label_confirmaddprop}" header="#{msg.label_addprop}"
					severity="alert" widgetVar="confirmationProperties">
					<p:commandButton id="confirm"
						update=":frmadd propertiesGlow :frmNew :frmlist"
						value="#{msg.label_yes}"
						oncomplete="confirmationProperties.hide(); dlgAdd.show();"
						actionListener="#{RepositoriesBean.addPropertiesDefaultYes()}"
						icon="accept" />
					<p:commandButton id="decline" value="#{msg.label_noonlydefault}"
						onclick="confirmationProperties.hide()"
						actionListener="#{RepositoriesBean.addPropertiesDefaultNo()}"
						icon="cancel" update=":frmNew :frmlist" />
				</p:confirmDialog>
			</h:form>
			<!-- Formulario para agregar propiedades -->
			<h:form id="frmadd">
				<p:dialog header="#{msg.label_addprop}" widgetVar="dlgAdd"
					resizable="false" modal="true" id="addDialog">
					<p:growl id="addGrowl" showDetail="false" sticky="true" />
					<h:outputText value="#{msg.label_repository}: " />
					<h:outputText value="#{RepositoriesBean.repositories.name}"
						style="font-weight:bold" />
					<h:panelGrid columns="1" style="margin-bottom:10px; width: 600px;"
						cellpadding="" id="panelProperties">
						<p:dataTable var="properties"
							value="#{RepositoriesBean.listProperties}"
							emptyMessage="#{msg.label_resultsnotfound}.">
							<p:column headerText="#{msg.label_proplabel}">
								<h:outputText value="#{properties.label}" />
							</p:column>
							<p:column headerText="#{msg.label_fieldtype}">
								<h:outputText value="#{properties.typeField.description}" />
							</p:column>
							<p:column headerText="#{msg.label_size}">
								<h:outputText value="#{properties.size}" />
							</p:column>
							<p:column headerText="#{msg.label_required}"
								style="width:12%; text-align: center;">
								<p:selectBooleanCheckbox value="#{properties.mandatory}"
									disabled="true" />
							</p:column>
						</p:dataTable>
					</h:panelGrid>
					<h:panelGrid columns="2" style="margin-bottom:10px; width: 600px;"
						cellpadding="" id="formProperties">
						<h:outputLabel for="label" value="#{msg.label_proplabel}: " />
						<p:inputText id="label" required="true" size="30"
							value="#{RepositoriesBean.label}" />
						<h:outputLabel for="type" value="#{msg.label_fieldtype}: " />
						<p:autoComplete value="#{RepositoriesBean.typeField}"
							id="basicPojo" completeMethod="#{RepositoriesBean.completeType}"
							var="p" itemLabel="#{p.description}" itemValue="#{p}"
							converter="PropertiesUserConverter" forceSelection="true" />
						<h:outputLabel for="size" value="#{msg.label_size}: " />
						<p:inputText id="size" required="true" size="5"
							value="#{RepositoriesBean.size}" />
						<h:outputText value="#{msg.label_required}: " />
						<p:selectBooleanCheckbox value="#{RepositoriesBean.mandatory}" />
						<f:facet name="footer">
							<p:commandButton id="submitButton" value="#{msg.label_save}"
								icon="save" actionListener="#{RepositoriesBean.addProperties}"
								update="panelProperties, formProperties" />
							<p:commandButton value="#{msg.label_finish}"
								oncomplete="dlgAdd.hide();" icon="accept"
								update="formProperties"
								actionListener="#{RepositoriesBean.cancel}" />
						</f:facet>
					</h:panelGrid>
				</p:dialog>
			</h:form>
			<br />
			<!-- Formulario lista de propiedades para usuarios -->
			<h:form id="frmlist">
				<p:growl id="listGlow" showDetail="true" />
				<p:dataTable var="repositories"
					value="#{RepositoriesBean.listRepositories}" paginator="true"
					rows="10"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					paginatorPosition="bottom"
					rowsPerPageTemplate="1,5,10,15,20,30">
					<h:inputHidden value="#{repositories.id}" />
					<p:column headerText="#{msg.label_name}">
						<h:outputText value="#{repositories.name}" />
					</p:column>
					<p:column headerText="#{msg.label_description}">
						<h:outputText value="#{repositories.description}" />
					</p:column>
					<p:column headerText="#{msg.label_organization}">
						<h:outputText value="#{repositories.organization.name}" />
					</p:column>
					<p:column headerText="#{msg.label_storage}">
						<h:outputText value="#{repositories.storage.name}" />
					</p:column>
					<p:column style="width:12%; text-align: center;">
						<p:commandButton oncomplete="editDialog.show()" icon="edit"
							title="#{msg.label_edit}" update=":frmEdit"
							actionListener="#{RepositoriesBean.prepareRepositorie(repositories.id)}" />
						<p:commandButton icon="grouprepo"
							oncomplete="addGroupDialog.show()"
							title="#{msg.label_editrepogroups}"
							actionListener="#{RepositoriesBean.prepareRepositorieGroup(repositories.id)}"
							update=":frmAddGroup" />
					</p:column>
				</p:dataTable>
			</h:form>
			<!-- Formulario para editar -->
			<h:form id="frmEdit">
				<p:dialog header="#{msg.label_editrepo}" widgetVar="editDialog"
					resizable="false" modal="true" id="editDialog">
					<p:growl id="editGrowl" showDetail="false" sticky="true" />
					<h:panelGrid columns="2" style="margin-bottom:10px; width: 400px;">
						<h:outputLabel for="name" value="#{msg.label_name}: " />
						<p:inputText id="name" required="true" size="30"
							value="#{RepositoriesBean.repositories.name}" />
						<h:outputLabel for="description"
							value="#{msg.label_description}: " />
						<p:inputTextarea rows="6" cols="33" id="description"
							value="#{RepositoriesBean.repositories.description}" />
						<f:facet name="footer">
							<p:commandButton value="#{msg.label_save}" icon="save"
								actionListener="#{RepositoriesBean.edit()}" id="editBtn"
								update=":frmlist,editDialog" oncomplete="editDialog.hide();" />
							<p:commandButton value="#{msg.label_cancel}"
								oncomplete="editDialog.hide();" icon="cancel" />
						</f:facet>
					</h:panelGrid>
				</p:dialog>
			</h:form>
			<!-- Formulario para agregar grupos al repositorio -->
			<h:form id="frmAddGroup">
				<p:dialog header="#{msg.label_addgroupstorepository}"
					widgetVar="addGroupDialog" resizable="false" modal="true"
					id="addGroupDialog">
					<p:growl id="addGroupGrowl" showDetail="true" escape="false" />
					<h:panelGrid columns="2" style="margin-bottom:10px; width: 400px;">

						<p:pickList id="pojoPickList"
							value="#{RepositoriesBean.listGroups}" var="groups"
							itemValue="#{groups}" itemLabel="#{groups.name}"
							converter="GroupConverter" showSourceControls="true"
							showTargetControls="true" showSourceFilter="true"
							showTargetFilter="true" filterMatchMode="contains">

							<f:facet name="sourceCaption">#{msg.label_freegroups}</f:facet>
							<f:facet name="targetCaption">#{msg.label_unitedtorepo}</f:facet>

							<p:ajax event="transfer"
								listener="#{RepositoriesBean.onTransfer}"
								update="addGroupGrowl, pojoPickList" />
						</p:pickList>

					</h:panelGrid>
				</p:dialog>
			</h:form>
		</p:panel>

		<p:confirmDialog header="Oooops!!!" severity="alert"
			visible="#{not empty param['expired']}" message="View has expired."
			widgetVar="confirmDlg">
			<p:commandButton type="button" value="OK" onclick="confirmDlg.hide()" />
		</p:confirmDialog>
	</ui:define>
</ui:composition>